package edu.wuster.blog.entity;

/*
 *
 * 统一响应结果实体类
 * */

import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {

    //响应码，0代表失败，1代表成功
    @JSONField(ordinal = 1)
    private Integer code;

    //提示信息
    @JSONField(ordinal = 2)
    private String msg;

    //返回的数据
    @JSONField(ordinal = 3)
    private Object data;

    //响应成功，无返回数据
    public static Result success() {
        return new Result(1, "success", null);
    }

    //响应成功，有返回数据
    public static Result success(Object data) {
        return new Result(1, "success", data);
    }

    //响应失败
    public static Result error(String msg) {
        return new Result(0, msg, null);
    }
}
